<template>
	<view class="p20">
		<wlk-navbar isFillHeight title="定制" :navbarType='3'></wlk-navbar>
		<view class="title fb f34 pl10">联系需求 <text class="sub f24 ml20">完善联系需求，我们将根据要求与您联系</text> </view>
		<from-item v-for="(item,index) in list" :required='item.required' v-model="item.content" :type='item.type'
			:key="index" :title="item.name" :subtitle="item.subtitle" :list='item.value'></from-item>
		<view class="mt80">
			<u-button text='提交' @click="send" type="primary"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				value: '',
				list: [],
				spotend: [],
				name: '',
			}
		},
		methods: {
			getForm() {
				uni.$u.http.post('from/getForm', {
					id: this.id
				}).then(res => {
					console.log(res.data)
					if (res.data) {
						res.data.map(item=>item.name.indexOf('目的地')!=-1?item.content=this.name:null)
						// res.data.map(item=>item.subtitle!=null?item.name+=item.subtitle:null)
						this.list = res.data;
					} else {
						this.notDiy = true;
					}
				})
			},
			send() {
				for (let item of this.list) {
					if (item.required && item.content == '') {
						uni.showToast({
							title: '请输入' + item.name,
							icon: "none"
						})
						return
					}
				}
				let data = this.list.map(item => {
					return {
						fid: item.fid,
						tid: item.id,
						value: item.content,
						uid: uni.getStorageSync('userInfo').id
					}
				})
				uni.$u.http.post('from/setForm', {
					data
				}).then(res => {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
					setTimeout(() => {
						if (res.code == 1) {
							uni.navigateBack()
						}
					}, 2000)
				})
			}
		},
		onLoad(options) {
			this.name = options.name || '',
			this.id = options.id || '',
			this.getForm()
		}
	}
</script>

<style scoped lang="scss">
	.title {
		border-left: 4px solid #4691e7;
	}
</style>